package simulator.meta.agent;

import java.util.LinkedList;

import javax.vecmath.Vector3d;

import simbad.sim.BallAgent;
import simbad.sim.SimpleAgent;
import simulator.config.Config;
import simulator.implementation.agent.AgentRobot;
import simulator.implementation.agent.BumperRobot;
import simulator.implementation.agent.CameraRobot;
import simulator.implementation.agent.IntelligentRobot;
import simulator.implementation.agent.LightRobot;
import simulator.implementation.agent.SonarRobot;
import simulator.implementation.agent.TestRobot;
import util.essential.SourceGetter;
import util.xmlmanager.elements.Attribute;
import util.xmlmanager.elements.Element;

public class AgentFactory {
	public static SimpleAgent getAgent(String typeOfRobotArchitecture,Vector3d vector,String agentName){
		final float DEFAULT_RADIUS = 1;
		return getAgent(typeOfRobotArchitecture,DEFAULT_RADIUS,vector,agentName);
	}
	public static SimpleAgent getAgent(String typeOfRobotArchitecture,float radius,Vector3d vector,String agentName){
		SourceGetter.xmlManager.addXMLDocument(Config.CONFIG_FILE_NAME);
		LinkedList<Element> tmp = SourceGetter.xmlManager.select("config.agent");
		byte typeOfRobotImplementation = -1;
		if(tmp.size() == 1){
			Element element = tmp.getFirst();
			Attribute attribute = element.getAttribute("type");
			if(attribute != null){
				typeOfRobotImplementation = Byte.parseByte(attribute.getValue());
			}
		}
		switch(typeOfRobotImplementation){
			case 1:{
				return new SonarRobot(vector, agentName);
			}
			case 2:{
				return new BumperRobot(vector, agentName);
			}
			case 3:{
				return new CameraRobot(vector, agentName);
			}
			case 4:{
				return new LightRobot(vector, agentName);
			}
			case 5:{
				return new IntelligentRobot(vector, agentName);
			}
			case 6:{
				return new TestRobot(vector, agentName);
			}
			case 7:{
				if(typeOfRobotArchitecture == null || typeOfRobotArchitecture.equals("normal")){
					return new AgentRobot(vector, agentName);
				}else if(typeOfRobotArchitecture.equals("spherical")){
					return new BallAgent(vector, agentName,radius);
				}
			}
			default:{//When typeOfRobot is -1.
				return new TestRobot(vector, agentName);
			}
		}
	}
}
